class CampsitesController < ApplicationController
  # GET /campsites
  # GET /campsites.xml
  before_filter :authorize
  layout "admin"

  def index
    @campsites = Campsite.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @campsites }
    end
  end

  # GET /campsites/1
  # GET /campsites/1.xml
  def show
    @campsite = Campsite.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @campsite }
    end
  end

  # GET /campsites/new
  # GET /campsites/new.xml
  def new
    @campsite = Campsite.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @campsite }
    end
  end

  # GET /campsites/1/edit
  def edit
    @campsite = Campsite.find(params[:id])
  end

  # POST /campsites
  # POST /campsites.xml
  def create
    @campsite = Campsite.new(params[:campsite])

    respond_to do |format|
      if @campsite.save
        flash[:notice] = 'Campsite was successfully created.'
        format.html { redirect_to(@campsite) }
        format.xml  { render :xml => @campsite, :status => :created, :location => @campsite }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @campsite.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /campsites/1
  # PUT /campsites/1.xml
  def update
    @campsite = Campsite.find(params[:id])

    respond_to do |format|
      if @campsite.update_attributes(params[:campsite])
        flash[:notice] = 'Campsite was successfully updated.'
        format.html { redirect_to(@campsite) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @campsite.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /campsites/1
  # DELETE /campsites/1.xml
  def destroy
    @campsite = Campsite.find(params[:id])
    @campsite.destroy

    respond_to do |format|
      format.html { redirect_to(campsites_url) }
      format.xml  { head :ok }
    end
  end
end
